home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / PRINTER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.8 KB  |  162 lines

  1. /*
  2.     file: printer.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1995: C. Moreau: Adding Gdos support
  8.     comments: 
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #ifdef __PUREC__ 
  14. #include <tos.h>
  15. #include <compend.h>
  16. #else
  17. #include <osbind.h>
  18. #endif
  19.  
  20. #include "e:\proging\c\libs\malib\alert.h"
  21.  
  22. #include "cursor.h"
  23. #include "init.h"
  24. #include "onepage.h"
  25. #include "printer.h"
  26. #include "wind.h"
  27.  
  28. #include "bfed_rsc.h"
  29.  
  30. /* 
  31.     locals functions
  32. */
  33. static void print_line(windowptr thewin,long    pos);
  34. static void pr_print(char *str);
  35.  
  36. /*
  37.     name: print
  38.     utility: send file or block to printer
  39.     comment: 
  40.     parameters:
  41.     return:
  42.     date: 1989
  43.     author: Jim Charlton
  44.     modifications:
  45.         1995: C. Moreau: 
  46. */
  47. void print(windowptr thewin)
  48. {
  49.  
  50.     if(!Bcostat(0))
  51.     {
  52.         rsc_alert(PRN_OFF);
  53.     }
  54.     else
  55.     {
  56.         long pos;
  57.  
  58.         while(Cconis())
  59.             Crawcin(); /* make sure io buffer clear */
  60.  
  61.         if(thewin->markson)
  62.         {
  63.             if (rsc_falert(PRN_BLK, thewin->title) == 1)    
  64.                 for (pos=thewin->startmark; pos<thewin->endmark+NB_DATA_IN_LINE;
  65.                         pos+=NB_DATA_IN_LINE)
  66.                 {
  67.                     print_line(thewin, pos);
  68.                     if (Cconis())
  69.                     {
  70.                         Crawcin();
  71.                          break;  /* any key to abort */
  72.                     }        
  73.                 }
  74.         }        
  75.         else
  76.         {
  77.             if (rsc_falert(PRN_FILE, thewin->title) == 1)    
  78.                 for (pos=0; pos<thewin->flen+NB_DATA_IN_LINE+1;
  79.                         pos+=NB_DATA_IN_LINE)
  80.                 {
  81.                     print_line(thewin, pos);
  82.                     if (Cconis())
  83.                     {
  84.                         Crawcin();
  85.                          break;  /* any key to abort */
  86.                     }        
  87.                 }
  88.         }
  89.     }        
  90. }
  91.  
  92. /*
  93.     name: print_line
  94.     utility: send a line to the printer
  95.     comment: 
  96.     parameters:
  97.         windowptr thewin: window data
  98.         long pos: aligned data
  99.     return:
  100.     date: 1989
  101.     author: Jim Charlton
  102.     modifications:
  103. */
  104. static void print_line(windowptr    thewin, long    pos)
  105. {
  106.     const long  l = (pos/NB_DATA_IN_LINE)*NB_DATA_IN_LINE;
  107.     unsigned num;
  108.     register int j,k;
  109.     char *hexa_ptr = hexa_str;
  110.     char *ascii_ptr = ascii_str;
  111.  
  112.     for (j=0; j < 16 ; j +=2 )
  113.     {  
  114.         for (k=0; k < 2  ; k++    )
  115.         {
  116.             if(l+j+k < thewin->flen-1)
  117.             {
  118.                 num = getbyte(thewin,l + j + k);
  119.                 if(num>31)
  120.                     *(ascii_ptr++) = num;
  121.                 else
  122.                     *(ascii_ptr++) = (unsigned)0x2E;
  123.                 strncpy(hexa_ptr, table+num*2,2);
  124.                 hexa_ptr += 2;
  125.             }
  126.             else
  127.             {
  128.                 strncpy(hexa_ptr, DOUBLE_BLANK, 2);
  129.                 hexa_ptr += 2;
  130.                 *(ascii_ptr++) = BLANK;
  131.             }
  132.         }
  133.         memcpy(hexa_ptr, DOUBLE_BLANK, 2);
  134.         hexa_ptr+=2;
  135.     }    
  136.     memcpy(hexa_ptr, DOUBLE_BLANK, 3);
  137.     hexa_ptr+=3;
  138.     pr_print(hexa_str);
  139.     *(ascii_ptr++)=0x0D;
  140.     *(ascii_ptr++)=0x0A;
  141.     *(ascii_ptr++)='\0';
  142.     pr_print(ascii_str);
  143. }
  144.  
  145. /*
  146.     name: pr_print
  147.     utility: send a string to the printer
  148.     comment: 
  149.     parameters:
  150.     return:
  151.     date: 1989
  152.     author: Jim Charlton
  153.     modifications:
  154. */
  155. static void pr_print(char *str)
  156. {
  157.     register int i;
  158.  
  159.     for (i=0;i<(strlen(str)+1);i++)
  160.         Bconout(0,str[i]);
  161. }    
  162.